package com.dg11185.nearshop.net.request;

import com.dg11185.libs.network.NetClient;
import com.dg11185.libs.utils.print.PrintUtils;
import com.dg11185.nearshop.net.NetCacheClient;
import com.dg11185.nearshop.net.response.GetAreaListResponse;
import com.dg11185.nearshop.net.response.GetBrandListResponse;
import com.dg11185.nearshop.net.response.GetIndustryListResponse;
import com.dg11185.nearshop.net.response.GetMerchantInfoResponse;
import com.dg11185.nearshop.net.response.GetMerchantListResponse;
import com.dg11185.nearshop.net.response.GetMerchantPhotoListResponse;
import com.dg11185.nearshop.net.response.GetMerchantStatsResponse;
import com.dg11185.nearshop.net.response.GetProvinceListResponse;
import com.dg11185.nearshop.net.response.GetReplyCommentListResponse;
import com.dg11185.nearshop.net.response.SendCommentMerchantResponse;

public class ShopData {

    // // 获取商家信息
    // public static void getJobType() {
    // JobTypeRequest request = new JobTypeRequest();
    // request.setActionListener(new
    // JobTypeRequest.ActionListener<JobTypeResponse>() {
    //
    // @Override
    // public void onSuccess(JobTypeResponse result) {
    // for(JobType t:result.jobTypes){
    // System.out.println(t.value);
    // }
    // }
    //
    // @Override
    // public void onFailure(int resultCode) {
    // }
    //
    // });
    // NetClient.httpGet(request);
    // }
    // 获取商家信息
    public static void getMerchantInfo(String merchantId) {
        GetMerchantInfoRequest request = new GetMerchantInfoRequest(merchantId);
        request.setActionListener(new GetMerchantInfoRequest.ActionListener<GetMerchantInfoResponse>() {

            @Override
            public void onSuccess(GetMerchantInfoResponse result) {
                PrintUtils.printo(result);
            }

            @Override
            public void onFailure(int resultCode) {
            }

        });
        NetClient.httpGet(request);
    }

    // 获取商家统计信息
    public static void getMerchantStats(String merchantId) {
        GetMerchantStatsRequest request = new GetMerchantStatsRequest(merchantId);
        request.setActionListener(new GetMerchantStatsRequest.ActionListener<GetMerchantStatsResponse>() {

            @Override
            public void onSuccess(GetMerchantStatsResponse result) {
                PrintUtils.printo(result);
            }

            @Override
            public void onFailure(int resultCode) {
            }

        });
        NetClient.httpGet(request);
    }

    // 获取商家列表
    public static void getMerchantList(String areaNum) {
        GetMerchantListRequest request = new GetMerchantListRequest("0001900017").encryption();
        request.setActionListener(new GetMerchantListRequest.ActionListener<GetMerchantListResponse>() {

            @Override
            public void onSuccess(GetMerchantListResponse result) {
                PrintUtils.printo(result);
            }

            @Override
            public void onFailure(int resultCode) {
            }

        });
        NetClient.httpGet(request);
    }

    // // 获取特惠日商家
    // public static void getDayMerList(String areaNum) {
    // GetDayMerListRequest request = new GetDayMerListRequest(areaNum,
    // "").encryption();
    // request.setActionListener(new
    // GetDayMerListRequest.ActionListener<GetDayMerListResponse>() {
    //
    // @Override
    // public void onSuccess(GetDayMerListResponse result) {
    // PrintUtils.printo(result);
    // }
    //
    // @Override
    // public void onFailure(int resultCode) {
    // }
    //
    // });
    // NetClient.httpGet(request);
    // }

    // 获取品牌（连锁商家）列表
    public static void getBrandList(String areaNum) {
        GetBrandListRequest request = new GetBrandListRequest(areaNum).encryption();
        request.setActionListener(new GetBrandListRequest.ActionListener<GetBrandListResponse>() {

            @Override
            public void onSuccess(GetBrandListResponse result) {
                PrintUtils.printo(result);
            }

            @Override
            public void onFailure(int resultCode) {
            }

        });
        NetClient.httpGet(request);
    }

    // 获取行业列表
    public static void getIndustryList(final NetListener<GetIndustryListResponse> listener) {
        GetIndustryListRequest request = new GetIndustryListRequest();
        request.setActionListener(new GetIndustryListRequest.ActionListener<GetIndustryListResponse>() {

            @Override
            public void onSuccess(GetIndustryListResponse result) {
                if (listener != null) {
                    listener.onSuccess(result);
                } else {
                    PrintUtils.printc(result.industries);
                }
            }

            @Override
            public void onFailure(int resultCode) {
                if (listener != null) {
                    listener.onFailue(resultCode);
                }
            }

        });
        NetClient.httpGet(request);
    }

    // 获取商家图片列表
    public static void getMerchantPhotoList() {
        GetMerchantPhotoListRequest request = new GetMerchantPhotoListRequest("12");
        request.setActionListener(new GetMerchantPhotoListRequest.ActionListener<GetMerchantPhotoListResponse>() {

            @Override
            public void onSuccess(GetMerchantPhotoListResponse result) {
                PrintUtils.printo(result);
            }

            @Override
            public void onFailure(int resultCode) {
            }

        });
        NetClient.httpGet(request);
    }

    // 获取商家主评论
    // public static void getMerchantCommentList(String merchantId) {
    // GetMerchantCommentListRequest request = new
    // GetMerchantCommentListRequest(merchantId).encryption();
    // request.setActionListener(new
    // GetMerchantCommentListRequest.ActionListener<GetMerchantCommentListResponse>()
    // {
    //
    // @Override
    // public void onSuccess(GetMerchantCommentListResponse result) {
    // PrintUtils.printo(result);
    // }
    //
    // @Override
    // public void onFailure(int resultCode) {
    // }
    //
    // });
    // NetClient.httpGet(request);
    // }

    // 获取评论的回复
    public static void getReplyCommentList() {
        GetReplyCommentListRequest request = new GetReplyCommentListRequest("", "");
        request.setActionListener(new GetReplyCommentListRequest.ActionListener<GetReplyCommentListResponse>() {

            @Override
            public void onSuccess(GetReplyCommentListResponse result) {
                PrintUtils.printo(result);
            }

            @Override
            public void onFailure(int resultCode) {
            }

        });
        NetClient.httpGet(request);
    }

    // 评论商家
    public static void commentMerchant(String merchantId, String content, String userId, String userName) {
        SendCommentMerchantRequest request = new SendCommentMerchantRequest(merchantId, content, userId, userName)
                .encryption();
        request.setActionListener(new SendCommentMerchantRequest.ActionListener<SendCommentMerchantResponse>() {

            @Override
            public void onSuccess(SendCommentMerchantResponse result) {
                PrintUtils.printo(result);
            }

            @Override
            public void onFailure(int resultCode) {
            }

        });
        NetClient.httpGet(request);
    }

    // 获取省份
    public static void getProvinceList() {
        GetProvinceListRequest request = new GetProvinceListRequest();
        request.setActionListener(new GetProvinceListRequest.ActionListener<GetProvinceListResponse>() {

            @Override
            public void onSuccess(GetProvinceListResponse result) {
                PrintUtils.printo(result);
            }

            @Override
            public void onFailure(int resultCode) {
            }

        });
        NetClient.httpGet(request);
    }

    public static int a = 0;

    // 获取省份
    public static void getAreaList(final NetListener<GetAreaListResponse> listener, String parentId) {
        GetAreaListRequest request = new GetAreaListRequest(parentId);
        request.setActionListener(new GetAreaListRequest.ActionListener<GetAreaListResponse>() {

            @Override
            public void onSuccess(GetAreaListResponse result) {
                if (listener != null) {
                    listener.onSuccess(result);
                } else {
                    PrintUtils.printc(result.areas);
                }
            }

            @Override
            public void onFailure(int resultCode) {
                if (listener != null) {
                    listener.onFailue(resultCode);
                } else {
                    a++;
                    System.out.println("wrong call back " + a);
                }
            }

        });
        NetClient.httpGet(request);
    }

    public static interface NetListener<T> {
        public void onSuccess(T result);

        public void onFailue(int resultCode);
    }
}
